package com.kl.model.pojo;

import com.kl.App;
import com.kl.constant.KeyParams;
import com.kl.enums.Image;
import com.kl.enums.State;
import com.kl.utils.ResourceUtil;
import lombok.Data;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.concurrent.ConcurrentMap;

/**
 * @author CC
 * time 2024-05-20
 * description
 */
@Data
public class Explode{
    static {
        try {
            BufferedImage e1 = ImageIO.read(new File(ResourceUtil.getSrcPath().concat(Image.EXPLODE_INIT.toString())));
            BufferedImage e2 = ImageIO.read(new File(ResourceUtil.getSrcPath().concat(Image.EXPLODE_MIDDLE.toString())));
            BufferedImage e3 = ImageIO.read(new File(ResourceUtil.getSrcPath().concat(Image.EXPLODE_END.toString())));
            ConcurrentMap<String, Object> cache = App.getCACHE();
            cache.put(KeyParams.EXPLODE_INIT, e1);
            cache.put(KeyParams.EXPLODE_MID, e2);
            cache.put(KeyParams.EXPLODE_END, e3);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }

    }

    private int x;
    private int y;
    private State state;
    private int life;

    public Explode(int y, int x) {
        this.y = y;
        this.x = x;
        this.life=9;
        this.state=State.ALIVE;
    }
    public void lifeDown(){
        while (life>0){
            --life;
        }
        this.state=State.DEATH;
    }
}
